<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个税计算器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            margin: 0;
            padding: 20px;
            display: flex; /* 使用Flexbox布局 */
            flex-direction: column; /* 纵向排列内容 */
            justify-content: center; /* 垂直居中 */
            align-items: center; /* 水平居中 */
            height: 100vh; /* 视口高度 */
            background-image: url("img/4.webp");
            background-size: 550px; /* 背景图片大小 */
            background-position: center; /* 背景图片位置 */
        }
        .container {
            max-width: 500px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            text-align: center; /* 文字居中 */
        }
        h2 {
            color: #007bff;
        }
        label {
            display: block;
            margin: 10px 0 5px;
            font-weight: bold;
        }
        input[type="text"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 15px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 16px;
        }
        button {
            width: 100%;
            padding: 10px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #0056b3;
        }
        #result {
            margin-top: 20px;
            padding: 10px;
            background-color: #e9ecef;
            border: 1px solid #ccc;
            border-radius: 4px;
            text-align: center;
            font-weight: bold;
        }
        a {
            display: block;
            margin-top: 20px; /* 适当的上下间距 */
            text-decoration: none;
            color: #007bff;
        }
        a:hover {
            text-decoration: underline;
        }
        p {
            margin-top: 20px; /* 适当的间距 */
        }
    </style>
    <script>
        function shuru() {
            var gongzi = document.getElementById("gongzi").value;
            document.getElementById("leiji").value = gongzi;
        }

        function jiesuan() {
            var gongzi = parseFloat(document.getElementById("gongzi").value) || 0;
            var shebao = parseFloat(document.getElementById("shebao").value) || 0;

            // 计算应纳税所得额
            var shui = gongzi - shebao; 
            var shuiLv = 0;

            // 应纳税所得额的税率计算
            if (shui <= 0) {
                shui = 0;
                shuiLv = 0;
            } else if (shui <= 3000) {
                shuiLv = 0.03; // 3%
            } else if (shui <= 12000) {
                shuiLv = 0.1; // 10%
            } else {
                shuiLv = 0.2; // 20%
            }

            var shuiKuan = shui * shuiLv;

            // 显示结果
            document.getElementById("shui").innerText = shui.toFixed(2);
            document.getElementById("shuiLv").innerText = (shuiLv * 100).toFixed(2) + "%";
            document.getElementById("jishu").value = shuiKuan.toFixed(2);
        }
    </script>
</head>
<body>
    <div class="container">
        <h2>个税计算器</h2>
        <label for="gongzi">收入类型：工资、薪金所得（税前）</label>
        <input type="text" id="gongzi" oninput="shuru()" placeholder="请输入本月工资">

        <label for="leiji">收入积累：</label>
        <input type="text" id="leiji" placeholder="自动填充" readonly>

        <label for="shebao">各项社会保险：</label>
        <input type="text" id="shebao" placeholder="请输入各项社会保险">

        <label for="leiji2">其他积累：</label>
        <input type="text" id="leiji2" placeholder="可选填写">

        <div id="result">
            应纳税所得额：<span id="shui" style="color:orange;">0.00</span><br>
            适用税率：<span id="shuiLv" style="color:orange;">0.00%</span><br>
            累计应缴税款：<input type="text" id="jishu" placeholder="计算结果" readonly>
        </div>
        
        <button onclick="jiesuan()">计算</button>
        <p><a href="ceshihe.html">点击返回首页</a></p>
        <p>© 2024 周露航</p>
    </div>
</body>
</html>
